var t = require("../../../@babel/runtime/helpers/interopRequireDefault"), a = t(require("../../../@babel/runtime/regenerator")), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), s = t(require("../dateParserTime")), i = getApp();

Page({
    data: {
        active: 0,
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        listData: [],
        msg_body: {
            changeTime: "时间",
            changeType: "类型",
            changeNum: "变动金额",
            afterChange: "变动后",
            order_sn: "订单编号",
            order_amount: "订单金额",
            mall_amount: "商城销售额",
            amount: "分红结算金额",
            dividend_amount: "分红奖励金额"
        },
        subTypeList: []
    },
    onLoad: function(t) {
        this.getSubType();
    },
    getSubType: function() {
        var t = this;
        return e(a.default.mark(function e() {
            var s;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    s = i.getNetAddresss("plugin.instation-message.api.message.get-sub-type"), i._postNetWork({
                        url: s,
                        data: {
                            type_id: 5
                        },
                        success: function(a) {
                            var e = a.data;
                            if (1 !== e.result) return t.tips(e.msg);
                            t.setData({
                                subTypeList: e.data
                            }), t.getListData();
                        }
                    });

                  case 2:
                  case "end":
                    return a.stop();
                }
            }, e);
        }))();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    gotoPages: function(t) {
        var a = t.currentTarget.dataset.page;
        "" != a && null != a && wx.navigateTo({
            url: a
        });
    },
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    initData: function() {
        this.data.page = 1, this.data.isLoadMore = !0, this.data.total_page = 0;
    },
    getListData: function() {
        var t = this;
        return e(a.default.mark(function e() {
            var n;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    t.initData(), n = i.getNetAddresss("plugin.instation-message.api.message.get-type-list"), 
                    i._postNetWork({
                        url: n,
                        data: {
                            type_id: 5,
                            sub_type: t.data.subTypeList[t.data.active].sub_type
                        },
                        success: function(a) {
                            var e = a.data;
                            if (1 !== e.result) return t.tips(e.msg);
                            e.data.data.forEach(function(t) {
                                t.created_at = (0, s.default)(t.created_at);
                            }), t.data.isLoadMore = !0, t.data.total_page = e.data.last_page, t.data.total_page || (t.data.total_page = 0), 
                            t.setData({
                                listData: e.data.data
                            });
                        }
                    });

                  case 3:
                  case "end":
                    return a.stop();
                }
            }, e);
        }))();
    },
    _getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page += 1;
            var a = i.getNetAddresss("plugin.instation-message.api.message.get-type-list");
            i._postNetWork({
                url: a,
                data: {
                    type_id: 5,
                    sub_type: this.data.subTypeList[this.data.active].sub_type,
                    page: this.data.page
                },
                success: function(a) {
                    var e = a.data;
                    if (t.data.isLoadMore = !0, 1 === e.result) {
                        var i = e.data.data, n = t.data.listData.concat(i);
                        i.forEach(function(t) {
                            t.created_at = (0, s.default)(t.created_at);
                        }), t.setData({
                            listData: n
                        });
                    } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1;
                }
            });
        }
    },
    changeTags: function(t) {
        console.log(t.detail.index, this.data.active), this.data.active = t.detail.index, 
        this.getListData();
    },
    tips: function(t) {
        return wx.showToast({
            title: t,
            icon: "none",
            duration: 2e3
        }), !1;
    }
});